import request from '/@/utils/request';
import other from '/@/utils/other';
import { AxiosResponse } from 'axios';

export interface ShortcutData {
  ID?: string;
  UserId?: string;
  MenuId?: string;
  MenuName: string;
  MenuIcon: string;
  MenuUrl: string;
  SortOrder?: number;
}

export interface ShortcutVm {
  Entity: ShortcutData;
}

export interface ShortcutSearchResult {
  ID: string;
  UserId: string;
  MenuId: string;
  MenuName: string;
  MenuIcon: string;
  MenuUrl: string;
  SortOrder: number;
}

export default function shortcutsApi() {
  return {
    // 获取用户常用功能列表
    getList: (data: object = {}) => {
      return request({
        url: '/api/SysUserFavorite/Search',
        method: 'post',
        data,
      });
    },

    // 获取单个常用功能详情
    get: (id: string | number) => {
      return request({
        url: `/api/SysUserFavorite/${id}`,
        method: 'get',
      });
    },

    // 新增常用功能
    add: (data: ShortcutVm) => {
      return request({
        url: '/api/SysUserFavorite/Add',
        method: 'post',
        data,
      });
    },

    // 编辑常用功能
    edit: (data: ShortcutVm) => {
      return request({
        url: '/api/SysUserFavorite/Edit',
        method: 'put',
        data,
      });
    },

    // 删除常用功能
    delete: (ids: (string | number)[]) => {
      return request({
        url: '/api/SysUserFavorite/BatchDelete',
        method: 'post',
        data: ids,
      });
    },

    // 批量删除常用功能
    batchDelete: (ids: (string | number)[]) => {
      return request({
        url: '/api/SysUserFavorite/BatchDelete',
        method: 'post',
        data: ids,
      });
    },

    // 导出功能
    export: (data: object) => {
      return request<any, Blob>({
        responseType: 'blob',
        url: '/api/SysUserFavorite/ExportExcel',
        method: 'post',
        data,
      }).then((response) => {
        other.downloadFile(response);
      });
    },

    // 导入功能
    import: (data: object) => {
      return request({
        url: '/api/SysUserFavorite/Import',
        method: 'post',
        data,
      });
    },
  };
} 